package com.tyqx.hashchainbiz.controller.shipping;

import com.tyqx.hashchainbean.module.ProductOut;
import com.tyqx.hashchainbean.module.ShippingInfo;
import com.tyqx.hashchainbean.vo.ProductOutVO;
import com.tyqx.hashchainbean.vo.QueryParamVo;
import com.tyqx.hashchainbean.vo.QueryTimeParamVo;
import com.tyqx.hashchainbean.vo.ShippingInfoVO;
import com.tyqx.hashchainbiz.service.QueryDonateService;
import com.tyqx.hashchainbiz.service.ShippingProductService;
import com.tyqx.hashchainbiz.service.TrackDonateService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "物流公司")
@RestController
@RequestMapping("/shippingProduct")
@CrossOrigin
public class ShippingProductController {

    @Resource
    private ShippingProductService shippingProductService;

    @RequestMapping(value="/saveShippingProduct", method = RequestMethod.POST)
    @ResponseBody
    public String saveShippingProduct(@RequestBody ShippingInfoVO shippingInfoVO) throws Exception {

        String msg="";
        ShippingInfo shippingInfo=new ShippingInfo();
        shippingInfo.setDonatee(shippingInfoVO.getDonatee());
        shippingInfo.setDonateId(shippingInfoVO.getDonateId());
        shippingInfo.setOperator(shippingInfoVO.getOperator());
        shippingInfo.setOutId(shippingInfoVO.getOutId());
        shippingInfo.setOutTime(shippingInfoVO.getOutTime());
        shippingInfo.setPlateNo(shippingInfoVO.getPlateNo());
        shippingInfo.setShipId(shippingInfoVO.getShipId());
        shippingInfo.setUserName(shippingInfoVO.getUserName());
        if(shippingProductService.shippingProduct(shippingInfo)>0){
            msg="添加物流公司成功";
        }else{
            msg="添加物流公司失败";
        }
        return msg;
    }

    @RequestMapping(value="/getShippingProductById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ShippingInfo> getShippingProductById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return shippingProductService.getShippingProductById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getShippingProductByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ShippingInfo> getProductOutByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return shippingProductService.getShippingProductByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
